/* @INLINE FILE plugins.bloc.js =============================================================
	* Utility functions
	* 
	* VAR
	* plugin_win - a ref to the plugin window
	* plugins_url - location of the shared plugin scripts
	* props - window properties for the plugin window
    * this.transliterator
	* this.transliteration
	* this.currlang -  the current language
	* 
	* FUNC
	* launch_plugin - Launch the plugin window
	* this.trlit - 	load transliterator api
	* this.trld - callback for load initializes control
	* this.open_trlit - opens the translit window
	* this.makeTransliteratable - enable translit in text inputs
	* this.setLang - set translit language
	* this.prep_for_translit - prepare for translit
	* this.doc - set up document sharing
    * launchDoc - launch document sharing
    * this.share_doc
	*/
	
	var plugin_win={};
	var plugins_url = "http://www.fastcatsoftware.com/plugins/";
	var props='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1';

	var launch_plugin = function (url,win_id,props,x,y) {
		if(plugin_win[win_id]&&plugin_win[win_id].closed){
			plugin_win[win_id]=null;
		}
		if(!plugin_win[win_id]){
			plugin_win[win_id]=window.open(url,win_id ,props+',width = '+(x?x:650)+',height = '+(y?y:470)+',left=' + (window.screen.width - 582) / 2
				   +  ',top=' + (window.screen.height - 605) / 2);
			plugin_win[win_id].focus();
			return true;
		}else{
			plugin_win[win_id].focus();
			return false;
		}
	};

	//Transliteration
	
	this.transliterator;
	this.transliteration=[0]; //opened
	this.currlang;

	this.trlit = function(){
			google.load("elements", "1", {
				packages:"transliteration",callback: this.trld
			});
			fc_chat.transliteration[0]=1;
	};
	
	this.trld = function() {
		var options = {
		  sourceLanguage: 'en',
		  destinationLanguage: fc_chat.currlang || 'ar',
		  transliterationEnabled: true,
		  shortcutKey: 'ctrl+g'
		};
		fc_chat.transliterator = new google.elements.transliteration.TransliterationControl(options);
	};

	this.open_trlit = function(n){
		if(n){
			close_tools();
		}
		if(!l){
	    	launch_plugin(
	    			_r + "html/transliteration_menu.html",
	    			'fc_trlitwin',
	    			props);
		}
    };
    
	this.makeTransliteratable = function(){
		var ids = ["fc_chat"];
		if($('fc_chat')){
			fc_chat.transliterator.makeTransliteratable(["fc_chat"]);
		}
		if($('fc_uChat')){
			fc_chat.transliterator.makeTransliteratable(["fc_uChat"]);
		}
		if($('fc_uChat2')){
			fc_chat.transliterator.makeTransliteratable(["fc_uChat2"]);
		}
		jQ("#fc_chat,#fc_uchat,#fc_uchat2").css({"font-size":"12px","line-height":"1.2em"});
	};
	
	this.setLang = function(){
		fc_chat.transliterator.enableTransliteration();
		fc_chat.transliterator.setLanguagePair(
        		google.elements.transliteration.LanguageCode.ENGLISH,
        		fc_chat.currlang);
	};
	
	var prep_for_translit = function(){
		if(fc_chat.transliterator&&fc_chat.currlang){
        	fc_chat.makeTransliteratable();
        	setTimeout("fc_chat.setLang()",200);
    	}
	};
	
	//share document
	this.doc = function(n){
		var uid=_t.uid;
		var uid2=(!n?_t.cU:_t.uid);
		if(n){
			close_tools();
		}
    	if(!l&&isAvl(uid2)&&a.o[uid2] == '1') {
    		l=true;
    		var pad_id = jGo.MD5.hex_md5(window.location.hostname)+uid;
        	launchDoc(uid,pad_id,1);
        	if(uid!=uid2){
	            var uStr = uid2.toString();
	            req = '000'+(43+(uid.toString()).length)+'n' + uStr.length + zpad_right(uStr)+'4'+pad_id;
	            sendReq();
        	}else{
        		l=false;
        	}
    	}
    };
    
    var launchDoc = function(u,p,showalert){
    	return launch_plugin(
    			_r+"html/document.html?a="+showalert+"&user_id=" + encodeURIComponent(extractShortName(get_screen_name(),'')) + "&pad_id="+p,
    			'fc_docwin'+u,
    			props);
    };
    
    this.share_doc = function(uid2,pad_id){
    	if(!l){
    		if(launchDoc(uid2,pad_id,0)){
    	    	clearTimeout(viewing_timeout);
    	    	viewing_timeout=setTimeout("fc_chat.viewing("+uid2+",'"+'fc_docwin'+uid2+"','5')",3000);
    		}
    	}
    };
    
	//Send a note
	this.note = function(n){
		var uid=(!n?_t.cU:_t.uid);
		if(n){
			close_tools();
		}
    	if(!l&&isAvl(uid)&&a.o[uid] == '1') {
        	launch_plugin(
        			_r + "html/notepad.html?uid="+uid+"&host="+jGo.MD5.hex_md5(window.location.hostname),
        			'fc_notewin'+uid,
        			props);
    	}
    };
    //post note
    this.p_note = function(to_room,uid,file){
    	if(!l){
	    	if(to_room!='1'&&!isAvl(uid)){
	    		showInfo(__(265,'Unable to send this message. The user is not available.'));
	    	}else if(uid==_t.uid&&to_room!='1'||(tg==0&&to_room=='1')){
		    		showInfo(__(341,'Sorry, unable to send this message.'));
	    	}else if(to_room!='1'&&a.o[uid] != '1') {
	    		showInfo(__(130));
	    	}else{
	    		var u=(uid!=_t.uid||to_room!='1'?uid:'').toString();
	    		var len = 62 + file.length;
	    		req=zpad_left(len) + 'n' + u.length + zpad_right(u)+'3'+'[['+plugins_url+'notepad/'+file+']]';
	            sendReq();
	    	}
    	}
    };
    //game menu
	this.m_games = function(){
		var uid = _t.cU;
		try{
			plugin_win['fc_gamewin'].close();
		}catch(err){}
    	if(!l&&isAvl(uid)&&a.o[uid] == '1') {
        	launch_plugin(
        			_r + "html/game_menu.html?uid2="+uid+"&nm="+encodeURIComponent(a.snm[uid]),
        			'fc_gamewin',
        			props);
    	}
    };
    //invite for a game
    this.inv_game = function(uid,vars,game){
    	if(!l&&uid!=_t.uid){
	    	if(!isAvl(uid)){
	    		showInfo(__(265,'Unable to send this message. The user is not available.'));
	    	}else if(a.o[uid] != '1') {
	    		showInfo(__(130));
	    	}else{
	    		var u=uid.toString();
	    		var len = 44 + game.length+vars.length;
	    		req=zpad_left(len) + 'n' + u.length + zpad_right(u)+'8'+jGo.MD5.hex_md5(window.location.hostname)+vars+'.'+game;
	            sendReq();
	    	}
    	}
    };
    //launch game window
    this.play_game = function(u,id,dimx,dimy,domain,typ){
    	if(!l){
	    	//check that user is online and not blocking
	    	if(!(a.o[u] == '1'&&isAvl(u))){
	    		showInfo(__(338),"Sorry, this user is not able to play at the moment.");
	    	}else{
	        	if(launch_plugin(
	        			_r + "html/games.html?x="+dimx+"&y="+dimy+"&id="+id+"&domain="+domain+"&typ="+typ+"&uid="+_t.uid+"&uid2="+u+"&nm="+encodeURIComponent(extractShortName(get_screen_name(),'')),
	        			'fc_gamewin'+u,
	        			props,dimx,dimy)){
		        	if(typ==0){
		        		var uStr = u.toString();
		        		vars = id + ',' + dimx + ',' + dimy;
		        		var len = 43 + vars.length;
		       		 	req = '000'+len+'n' + uStr.length + zpad_right(uStr)+'9'+domain+vars;
		       		 	sendReq();
		        	}
	        	}
	    	}
    	}
    };
	//Whiteboard from dabbleboard
	this.wb = function(n){
		var uid=_t.uid;
		var uid2=(!n?_t.cU:_t.uid);
		if(n){
			close_tools();
		}
    	if(!l&&isAvl(uid2)&&a.o[uid2] == '1') {
    		l=true;
        	var _user_id=encodeURIComponent(get_screen_name() + ' at ' + jGo.MD5.hex_md5(window.location.hostname));
            var _user_key=jGo.MD5.hex_md5("1");
            var _drawing_id="1";
            var _drawing_key=jGo.MD5.hex_md5("1");
        	launch_plugin(
        			plugins_url+"whiteboard.html?user_id="+_user_id+"&user_key="+_user_key+"&drawing_user_id="+_user_id+"&drawing_user_key="+_user_key+"&drawing_id="+_drawing_id+"&drawing_key="+_drawing_key,
        			'fc_whiteboardwin'+uid,
        			props);
        	if(uid!=uid2){
	            var uStr = uid2.toString();
	            req = '00043n' + uStr.length + zpad_right(uStr)+'1'+jGo.MD5.hex_md5(window.location.hostname);
	            sendReq();
        	}else{
        		l=false;
        	}
    	}
    };
	this.share_wb = function(uid,uid2,user){
		if(!l){
			var _user_id=encodeURIComponent(get_screen_name() + ' at ' + jGo.MD5.hex_md5(window.location.hostname));
	        var _user_key=jGo.MD5.hex_md5("1");
	        var _drawing_user_key=jGo.MD5.hex_md5("1");
	        var _drawing_user_id=user.replace(/%22/g, '"').replace(/%27/g, "'").replace(/%25/g, '%');
	        var _drawing_id="1";
	        var _drawing_key=jGo.MD5.hex_md5("1");
	    	var url=plugins_url+"whiteboard.html?uid="+uid2+"&user_id="+_user_id+"&user_key="+_user_key+"&drawing_user_id="+_drawing_user_id+"&drawing_user_key="+_drawing_user_key+"&drawing_id="+_drawing_id+"&drawing_key="+_drawing_key;
	    	var win_id='fc_whiteboardwin'+uid2;
	    	if(launch_plugin(url,win_id,props)){
	    		clearTimeout(viewing_timeout);
	    		viewing_timeout=setTimeout("fc_chat.viewing("+uid2+",'"+win_id+"','2')",3000);
			}
		}
    };
    this.viewing = function(u,win_id,typ){
    	if(plugin_win[win_id]&&plugin_win[win_id].closed){
			return false;
		}
		 var uStr = u.toString();
		 req = '00011n' + uStr.length + zpad_right(uStr)+typ;
		 sendReq();
    };
    
	//Translator
    var translator = {
    		on:0,
    		cur_lang:'en',
    		init:0
    };
    var translate = function(_txt,_id,_k) {
        (function(){
	        var id = _id;
	        var k = _k;
	        var txt = _txt;
	        var s = document.createElement("script");
	        s.src = config.trans_url+"Detect?oncomplete=fc_detect_"+id+"&appId="+config.trans_appid+"&text=" + txt;
	        document.getElementsByTagName("head")[0].appendChild(s);
	        window['fc_detect_'+id] = function(response) { 
	        	if(response!=translator.cur_lang){
			   	     var s = document.createElement("script");
			   	     s.src = config.trans_url+"Translate?oncomplete=fc_translate_"+id+"&appId="+config.trans_appid+"&from=" + encodeURIComponent(response) + "&to=" + translator.cur_lang + "&text=" + txt;
			   	     document.getElementsByTagName("head")[0].appendChild(s);
	        	}
	        };
	        window['fc_translate_'+id] = function(response) {
	        	if(response!=""){
	        		response = response.replace(/</g, '%26lt;').replace(/>/g, '%26gt;');
	        		if(private_chat_panel&&k!=8)scr2($(id),(k==6?chatroom_panel:private_chat_panel),1, "<br>(" + response+")");
	        		if(k==8&&(tg == '0'||toggle_new_messages)){
	        			scr2($(id), jQ('#fc_view_msgs')[0], 3, "<br>(" + response+")");
	        		}
	        	}
	        };
        })();
    };
    this.set_translator = function(val){
    	translator.on = (val=='_off'?0:1);
    	put_cdata((val=='_off'?'0':'1'),10);
    	translator.cur_lang=val;
    	put_cdata(val,11);
    };
    
    //plugins.bloc.js =============================================================@END FILE*/